<?php

namespace app\admin\controller;
class Link extends base
{


    public function index()
    {

        $list = $this->model
            ->order('sort desc')
            ->paginate();
        $this->assign('num', $this->model->count());
        $this->assign('list', $list);
        return $this->fetch();
    }

    /**
     * 保存
     */
    public function save()
    {
        if (!$this->request->isPost()) {
            return ajax_info('请求失败');
        }
        $data = $this->request->post();
        $result = $this->validate($data, 'Link');
        if (true !== $result) {
            return ajax_info($result);
        }
        if(!empty($data['id'])){
           return $this->update($data);
        }

        $res = $this->model->allowField(true)->save($data);
        if ($res) {
            return ajax_info('保存成功','y');
        } else {
            return ajax_info('添加失败');
        }
    }
}
